home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
3D Images
/
3D Images.iso
/
programs
/
amiga
/
rayshade
/
libshade
/
misc.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-01-12
|
5KB
|
247 lines
/*
* misc.c
*
* Copyright (C) 1989, 1991, Craig E. Kolb
* All rights reserved.
*
* This software may be freely copied, modified, and redistributed
* provided that this copyright notice is preserved on all copies.
*
* You may not distribute this software, in whole or in part, as part of
* any commercial product without the express consent of the authors.
*
* There is no warranty or other guarantee of fitness of this software
* for any purpose. It is provided solely "as is".
*
* misc.c,v 4.1 1994/08/09 08:04:33 explorer Exp
*
* misc.c,v
* Revision 4.1 1994/08/09 08:04:33 explorer
* Bump version to 4.1
*
* Revision 1.1.1.1 1994/08/08 04:52:17 explorer
* Initial import. This is a prerelease of 4.0.6enh3, or 4.1 possibly.
*
* Revision 4.0.1.1 92/01/14 18:29:05 cek
* patch3: Added support for switching cpp on/off.
*
* Revision 4.0 91/07/17 14:46:31 kolb
* Initial version.
*
*/
#include "rayshade.h"
#ifdef RUSAGE
#include <sys/time.h>
#include <sys/resource.h>
#else
#ifdef TIMES
#include <sys/types.h>
#include <sys/times.h>
#include <sys/param.h>
#endif
#endif
#include "options.h"
#include "stats.h"
#include "libcommon/common.h"
#include "viewing.h"
#include "zbuf.h"
Float RSabstmp; /* Temporary value used by fabs macro. Ugly. */
static void RSmessage();
#ifdef AMIGA
#ifndef __GNUC__
extern FILE *popen();
#endif
extern FILE *popen2();
#endif
/*
* Open input file and call yyparse().
*/
void
RSReadInputFile()
{
extern FILE *yyin; /* lex/yacc file pointer */
extern char yyfilename[];
#if defined(CPPSTDIN) && defined(POPEN)
char cmd[BUFSIZ];
#ifdef AMIGA
if (Options.SAScpp) {
if (Options.cppargs != (char *)NULL)
sprintf(cmd, "%s %s ", SASCPPSTDIN, Options.cppargs);
else
/* fromstdin */
sprintf(cmd, "%s %s ", SASCPPSTDIN, SASCPPMINUS);
}else{
#endif
if (Options.cppargs != (char *)NULL)
sprintf(cmd, "%s %s ", CPPSTDIN, Options.cppargs);
else
/* fromstdin */
sprintf(cmd, "%s %s ", CPPSTDIN, CPPMINUS);
#ifdef AMIGA
}
#endif
if (Options.inputname == (char *)NULL) {
(void)strcpy(yyfilename, "stdin");
} else {
(void)strcpy(yyfilename, Options.inputname);
(void)strcat(cmd, Options.inputname);
}
if (Options.cpp) {
#ifdef AMIGA
if (Options.SAScpp)
yyin = popen2(cmd);
else
#endif
yyin = popen(cmd, "r");
if (yyin == (FILE *)NULL)
RLerror(RL_PANIC, "popen of \"%s\" failed!\n", cmd);
} else {
#endif
if (Options.inputname == (char *)NULL) {
yyin = stdin;
(void)strcpy(yyfilename, "stdin");
} else {
(void)strcpy(yyfilename, Options.inputname);
yyin = fopen(Options.inputname, "r");
if (yyin == (FILE *)NULL)
RLerror(RL_PANIC,
"Cannot open %s.\n",Options.inputname);
}
#if defined(CPPSTDIN) && defined(POPEN)
}
#endif
/*
* Initialize symbol table.
*/
SymtabInit();
if (Options.zbufprint)
zbuffer.rayfile = strsave (yyfilename);
(void)yyparse();
}
void
OpenStatsFile()
{
if (Options.statsname == (char *)NULL || Stats.fstats != stderr)
return; /* Not specified or already opened. */
Stats.fstats = fopen(Options.statsname, "w");
if (Stats.fstats == (FILE *)NULL) {
RLerror(RL_PANIC,
"Cannot open stats file %s.\n", Options.statsname);
}
}
void
RLerror(level, pat, arg1, arg2, arg3)
int level;
char *pat, *arg1, *arg2, *arg3;
{
switch (level) {
case RL_ADVISE:
if (!Options.quiet)
RSmessage("Warning", pat, arg1, arg2, arg3);
break;
case RL_WARN:
RSmessage("Warning", pat, arg1, arg2, arg3);
break;
case RL_ABORT:
RSmessage("Error", pat, arg1, arg2, arg3);
exit(1);
break;
case RL_PANIC:
RSmessage("Fatal error", pat, arg1, arg2, arg3);
exit(2);
break;
default:
RSmessage("Unknown error", pat, arg1, arg2, arg3);
exit(3);
}
}
static void
RSmessage(type, pat, arg1, arg2, arg3)
char *type, *pat, *arg1, *arg2, *arg3;
{
extern FILE *yyin;
extern int yylineno;
extern char yyfilename[];
if (yyin) {
/*
* cleanup() hasn't nulled yyin, so line #
* info is valid.
*/
fprintf(stderr,"%s: %s: %s, line %d: ",
Options.progname, type,
yyfilename == (char *)NULL ? "stdin" :
yyfilename, yylineno);
} else {
fprintf(stderr,"%s: %s: ", Options.progname, type);
}
fprintf(stderr, pat, arg1, arg2, arg3);
}
#ifdef RUSAGE
void
RSGetCpuTime(usertime, systime)
Float *usertime, *systime;
{
struct rusage usage;
getrusage(RUSAGE_SELF, &usage);
*usertime = (Float)usage.ru_utime.tv_sec +
(Float)usage.ru_utime.tv_usec / 1000000.;
*systime = (Float)usage.ru_stime.tv_sec +
(Float)usage.ru_stime.tv_usec / 1000000.;
}
#else
#ifdef TIMES
void
RSGetCpuTime(usertime, systime)
Float *usertime, *systime;
{
extern CLOCKTYPE times();
struct tms time;
(void)times(&time);
*usertime = (Float)time.tms_utime / (Float)HZ;
*systime = (Float)time.tms_stime / (Float)HZ;
}
#else /* !RUSAGE && !TIMES */
#ifdef AMIGA
void
RSGetCpuTime(usertime, systime)
Float *usertime, *systime;
{
long c[2];
extern long InitTime[2];
timer(c);
*usertime = (Float)c[0] + (Float)c[1]/1000000.0 -
((Float)InitTime[0] + (Float)InitTime[1]/1000000.0);
*systime = 0;
}
#else
void
RSGetCpuTime(usertime, systime)
Float *usertime, *systime;
{
*usertime = *systime = 0.;
}
#endif
#endif /* TIMES */
#endif /* RUSAGE */